package model;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import model.builders.ItineraryBuilder;


public class Population {
    
    private final List<Itinerary> population = new ArrayList<>();
    private final Graph graph;
    private static Random random = new Random();
    
    public Population(Graph graph, int amount) {
        this.graph = graph;
        for(int i = 0; i < amount; i++) {
            population.add(new ItineraryBuilder(graph).fill().build());
        }
    }

    public List<Itinerary> getPopulation() {
        return population;
    }
    
    public Itinerary getRandomItineraryFromPopulation() {
        return population.get(random.nextInt(population.size()));
    }
    
    public Graph getGraph() {
        return graph;
    }
    
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for(Itinerary itin : population) {
            sb.append(itin + "\n");
        }       
        return sb.toString();
    }


}
